package com.zzz.schedule.dao.impl;

import com.zzz.schedule.dao.BaseDao;
import com.zzz.schedule.dao.SysScheduleDao;
import com.zzz.schedule.pojo.SysSchedule;

import java.util.List;

/*
 * @author zzr
 * @date: 2025/07/14  00:09
 * @description:
 */
public class SysScheduleDaoImpl extends BaseDao implements SysScheduleDao {

    /**
     * 添加日程方法实现类
     * @param schedule 将日程数据以 SysSchedule 实体类对象形式入参
     * @return
     */
    @Override
    public int addSchedule(SysSchedule schedule) {
        String sql = "insert into sys_schedule values(DEFAULT,?,?,?)";
        int rows = baseUpdate(sql,schedule.getUid(),schedule.getTitle(),schedule.getCompleted());
        return rows;
    }

    /**
     * 返回所有用户日程
     * @return 将所有的日程放入一个 List<SysSchedule> 集合中返回
     */
    @Override
    public List<SysSchedule> findAll() {
        String sql = "select sid,uid,title,completed from sys_schedule";
        List<SysSchedule> sysScheduleList = baseQuery(SysSchedule.class, sql);
        return sysScheduleList;
    }

    /**
     * 通过 uid 返回所有对应的日程
     * @param uid
     * @return
     */
    @Override
    public List<SysSchedule> finItemListByUid(int uid) {
        String sql = "select sid,uid,title,completed from sys_schedule where uid = ?";
        List<SysSchedule> itemList = baseQuery(SysSchedule.class, sql, uid);
        return itemList;
    }

    @Override
    public Integer addDefault(int uid) {
        String sql = "insert into sys_schedule values (DEFAULT,?,'请输入日程',0)";
        return baseUpdate(sql, uid);
    }

    @Override
    public Integer updateSchedule(SysSchedule schedule) {
        String sql = "update sys_schedule set title = ?,completed = ? where sid = ?";
        return baseUpdate(sql,schedule.getTitle(),schedule.getCompleted(),schedule.getSid());
    }

    @Override
    public Integer removeSchedule(int sid) {
        String sql = "delete from sys_schedule where sid = ?";
        return baseUpdate(sql, sid);
    }
}
